fn main() {
    do_say("hello, world!", say);
    no_copy();
    copy();
    no_copy_withmove();
    copy_withmove();
}

fn say(s : &str) {
    println!("{}",s);
}

fn do_say(l : &str, dos: fn(&str)){
    dos(l);
}

fn no_copy(){
    // 闭包修改 mut 非copy
    let mut m = String::from("hello ,");
    // mut
    let mut change_m = || {
        m.push_str("world !")
    };
    change_m();

    println!("{}",m);
}

fn copy(){
    // 闭包修改 mut copy
    let mut m = 1;

    // mut
    let mut change_m = || {
        m += 1 ;
    };

    change_m();
    println!("{}" , m);
}

fn no_copy_withmove(){
    // 闭包修改 mut 非copy
    let mut m = String::from("hello ,");
    let m_s = &mut m;
    // mut
    let mut change_m = move || {
        m_s.push_str("11111");
    };

    change_m();
    println!("{}",m);
}

fn copy_withmove(){
    // 闭包修改 mut copy
    let mut m = 1;
    
    // mut
    let mut change_m = move || {
        m += 1 ;
    };

    change_m();

    println!("{}" , m);
}
